<?php
require(dirname(dirname(__FILE__)) . '/includes/init.php');
/*
1, 表示雅虎
2, 表示GMAIL
3, 表示HOTMAIL
4, 表示testsend
5, 表示AOL
6, 表示VERIFY
7, 表示others
*/
// echo $userActionArr['unsub'];exit;
$type = 2;   //define sysbolic
$table = "gmail"; //unique table

$sql = "select * from ".$table." where flag = 0 and unsubscribe = 0 limit 0,".$num."";
$resultArr = $GLOBALS['db']->dbfetchAll($sql);
if (empty($resultArr)) {
	$sql = "update ".$table." set flag = 0";
	$GLOBALS['db']->dbquery($sql);
	$sql = "select * from ".$table." where flag = 0 and unsubscribe = 0 limit 0,".$num."";
	$resultArr = $GLOBALS['db']->dbfetchAll($sql);	
}
// echo "<pre>";
// print_r($resultArr);exit;

$sql = "select templateId from num where emailNumType = ".$type." and flag = 0 order by id asc  limit 0,1";
$numArr = $GLOBALS['db']->dbGetRow($sql);

$sql = "select * from template where id = ".$numArr['templateId']."";
$template = $GLOBALS['db']->dbGetRow($sql);
//if tempate's title is empty,don't create anything
if(empty($template['title'])||empty($template['content'])){
	exit;
}
foreach ($resultArr as $key => $value) {
	$content = formatContent($unsubUrlArr, $userActionArr, $template['content'], $value['address'], $value['id'],$value['type'],$numArr['templateId']);
	$sql = "insert into tempTemplate(address, title, content, type, flag) values('".$value['address']."', '".$template['title']."', '".$content."', ".$type.", '0')";
	$GLOBALS['db']->dbquery($sql);
	$sql = "update ".$table." set flag = 1 where id = ".$value['id']."";
	$GLOBALS['db']->dbquery($sql);
	sendLog("num", $template['id'], $type);
}
?>